<template>
  <div class="admin-container">
    <div class="flexWithJusBetween mg-B20">
      <div class="title">企业资料列表</div>
    </div>
    <div v-show="queryType == false">
        <el-form ref="warehouseForm" label-width="80px" :inline="true">
          <el-form-item label="关键词">
            <el-input
              prefix-icon="el-icon-search"
              v-model="query.keyword"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="填报时间">
            <el-date-picker
              v-model="query.date"
              value-format="yyyy-MM-dd"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-button
            style="margin-left: 10px"
            icon="el-icon-search"
            type="primary"
            @click="submitQuery"
            >查询
          </el-button>
          <el-button
            style="margin-left: 10px"
            icon="el-icon-refresh-right"
            type="info"
            @click="resetQuery"
            >重置
          </el-button>
        </el-form>
      </div>
      <el-tabs v-model="status" @tab-click="handleClick">
        <el-tab-pane label="待审" name="1">
          <listTable :tableData="tableData" :dict="dict" @audit="audit" type="audit"></listTable>
        </el-tab-pane>
        <el-tab-pane label="已审" name="2">
          <listTable :tableData="tableData" :dict="dict" type="view"></listTable>
        </el-tab-pane>
        <el-tab-pane label="驳回" name="3">
          <listTable :tableData="tableData" :dict="dict" type="view"></listTable>
        </el-tab-pane>
        <el-tab-pane label="订正" name="4">
          <listTable :tableData="tableData" :dict="dict" @edit="edit" type="edit"></listTable>
        </el-tab-pane>
      </el-tabs>
      <!-- <el-table border :data="tableData" style="width: 100%" align="center">
        <el-table-column prop="name" label="企业名称" align="center"> </el-table-column>
        <el-table-column prop="linkman" label="负责人" align="center"  > </el-table-column>
        <el-table-column prop="phone" label="负责人联系方式" align="center"  > </el-table-column>
        <el-table-column prop="registerAddress" label="注册地址" align="center"> </el-table-column>
        <el-table-column prop="officeAddress" label="办公地址" align="center"> </el-table-column>
        <el-table-column label="企业状态" align="center" >
          <template slot-scope="scope">
            <div>{{companyStatusFormate("company_status-"+scope.row.status)}}</div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="auditCompany(scope.row)"
              >审核公司</el-button
            >
            <el-button type="text" size="small" @click="auditProject(scope.row)"
              >审核项目列表</el-button
            >
          </template>
        </el-table-column>
      </el-table> -->
      <el-footer class="el-footerBox">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="pageSize"
          :current-page.sync="pageNum"
          @current-change="getcompanyList"
        >
        </el-pagination>
      </el-footer>
  </div>
</template>

<script>
import permission from '@/directive/permission/index.js' // 权限判断指令
import utils from "@/utils/utils.js";
import listTable from "./listTable";
import { list as companyList } from "@/api/adminCompany";
import { find as projectFind } from "@/api/project";
import { list as projectActivityList } from "@/api/projectActivity";

export default {
  directives: { permission },
  components: {listTable},
  name: "project",
  data() {
    return {
      queryType: false,
      query: {
        keyword: "",
        date:"",
        startDate:"",
        endDate:""
      },
      total:0,
      pageNum:1,
      pageSize:20,
      tableData: [],
      status:'1',

      //字典信息
      dict:{},
      companyStatusDict:[],
      companyStatusDictPromise:"",
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    console.log('执行了created--',);
    this.companyStatusDictPromise = utils.getDictList("company_status", (res) => {
      this.dict.companyStatusDict = res.data;
    });
  },

  mounted() {
    let _this = this
    console.log('执行了mounted--',);
    Promise.all([ this.companyStatusDictPromise]).then(
      (res) => {
        //console.log("字典已经全部加载完成--");
        _this.getcompanyList()
      }
    );
  },

  destroyed() {},

  methods: {

    //获取公司列表
    getcompanyList() {
      let _this = this
      let params = new URLSearchParams();
      params.append("status", _this.status);
      params.append("startDate", _this.query.startDate);
      params.append("endDate", _this.query.endDate);
      params.append("keyword", _this.query.keyword);
      params.append('pageNum', _this.pageNum);
      params.append('pageSize', _this.pageSize);
      companyList(params)
        .then((res) => {
          console.log("companyList成功获取数据--", res);
          if (res.type == "success") {
            this.tableData = res.data.data;
            this.total = res.data.total
            if(this.tableData.length > 0){
              this.tableData.map(item => {
            item.createDate = utils.dateFormatter(item.createDate);
              })
              }
          }
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    },

    //tab切换
    handleClick(tab, even){
      console.log('tab--',this.status);
      this.getcompanyList()
    },

    //条件查询
    submitQuery() {
      console.log('this.query.date--',this.query);
      if(!utils.isNull(this.query.date)){
        this.query.startDate = this.query.date[0]
        this.query.endDate = this.query.date[1]
      }
      this.getcompanyList();
    },

    //条件查询
    resetQuery() {
      this.query = {
        keyword: "",
        date:"",
        startDate:"",
        endDate:""
      },
        this.getcompanyList();
    },


    //查看公司
    viewCompany(data) {
      console.log('data--',data);
      this.$router.push({
        path: "/company/view",
        query: {companyId: data.id },
      });
    },

    //条件查询
    submitQuery() {
      console.log('this.query.date--',this.query);
      if(!utils.isNull(this.query.date)){
        this.query.startDate = this.query.date[0]
        this.query.endDate = this.query.date[1]
      }
      this.getcompanyList();
    },

    //条件查询
    resetQuery() {
      this.query = {
        keyword: "",
        date:"",
        startDate:"",
        endDate:""
      },
        this.getcompanyList();
    },

    //审核公司
    audit(data){
      console.log('data--',data);
      this.$store.dispatch("user/setCloseAliveName", 'companyAudit')
      this.$router.push({
        path: "/company/audit",
        query: {companyId: data.id, type: "audit"  },
      });
    },

    //订正
    edit(data){
      console.log('data--',data);
      this.$store.dispatch("user/setCloseAliveName", 'companyAudit')
      this.$router.push({
        path: "/company/audit",
        query: {companyId: data.id, type: "edit" },
      });
    },

    //审核项目列表
    auditProject(data){
      console.log('data--',data);
      this.$router.push({
        path: "/project/auditList",
        query: {companyId: data.id },
      });
    },

    companyStatusFormate(data) {
      return utils.selectDictLabel(this.companyStatusDict, data);
    },
  },
};
</script>

<style lang="scss" scoped>
.admin-container{
  padding: 20px;
}

.el-pagination {
  display:block;
}
</style>
